﻿using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Text;

namespace WebServices
{
    public static class SingleServiceACollectionExtension
    {
        public static IServiceCollection AddSingleServiceA(this IServiceCollection services, string ident)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddOptions();

            // 设置断线自动恢复
            var factory = new SingleServiceA(ident,services.BuildServiceProvider().CreateScope().ServiceProvider.GetRequiredService<ILogger<SingleServiceA>>());

            services.Add(ServiceDescriptor.Singleton(factory));
            //services.Add(ServiceDescriptor.Singleton(factory.CreateInstance()));
            return services;
        }
    }
}
